package tw.com.softleader.reins.demo.book.app;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import tw.com.softleader.reins.demo.book.dao.BookDao;
import tw.com.softleader.reins.demo.book.entity.Book;

public class BookDummyDataInserter{
	public static void main(String[] args) {
		
		BookDao bookDao;
		bookDao = new BookDao();
		List<Book> books = bookDao.findAll();
		Long maxId = 0L;
        System.out.println("開始尋找最大值");
        for (Iterator<Book> it = books.iterator(); it.hasNext();) {
                maxId = it.next().getId();
        }
		System.out.println("開始輸入資料");
		books = new ArrayList<Book>();
		Book book = null;
		int result = 0;
		for (Long i = maxId+1; i <= maxId+100; i++) {
			book = new Book();
			book.setTitle("TitleName"+i);
			book.setWriter("Writer"+i);
			book.setPublication(new Timestamp(new Date().getTime()));
			book.setIsbn("ISBN 0-00000-"+(i/100>10?(i/10):((i/10)>10?"0"+(i/10):"00"+(i/10)))+"-"+(i%10));
			books.add(book);
		}
		bookDao.insert(books);
		System.out.println("\n成功輸入資料");
	}

}
